package com.myapplication;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.FrameLayout;

public class TestFrameLayout extends FrameLayout {
    private static final String TAG = TestFrameLayout.class.getSimpleName();

    private CustomViewPager mPager;

    public TestFrameLayout(@NonNull Context context) {
        super(context);
    }

    public TestFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public TestFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setPager(CustomViewPager pager) {
        this.mPager = pager;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean ret= super.onTouchEvent(ev);
        Log.i(TAG, "onTouchEvent[" + ev.getAction() + "]=" + ret);
        return ret;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        boolean ret= super.onInterceptTouchEvent(ev);
        Log.i(TAG, "onInterceptTouchEvent[" + ev.getAction() + "]=" + ret);
        return ret;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        boolean ret = super.dispatchTouchEvent(ev);

        if (ret && mPager != null && mPager.isBeginDragged()) {
            return true;
        }

        Log.i(TAG, "dispatchTouchEvent[" + ev.getAction() + "]=" + ret);
        return getChildAt(0).dispatchTouchEvent(ev);
    }
}
